Our lecturer gave us a program to look over in the holidays. Unfortunately I think he has forgotten we haven’t done any file handling in C yet. I’ve had a look around on some other websites to see if I can self teach myself some stuff. In my opinion I think from what I have picked up this piece of code should work? I’m trying to add a name to a txt file that already has some data in it …
From the examples I read online they were only printing text already present in the source code into the text file. But I am assuming that it’s possible to add the content of a variable to a text file?
When I run the program I enter a name and then press enter and the program closes. When I check the text file nothing has changed at all. Please help
Chris
Code:
void add_student()
{
char student_name[25];
printf("\nPlease enter a students name to add them to the data base.");
scanf("%24s",&student_name);
FILE *fp;
fp = fopen("collegerecord.txt","a");
fprintf(fp,"s%",student_name);
fclose(fp);
//puts("Function associated with menu option 'b' called sucessfully");
//getch();
}